var requestHandler = {
  params: {},
  success: function (res) {
    // success  
  },
  fail: function () {
    // fail  
  },
}

//GET请求  
function GET(API_URL,requestHandler) {
  
  request('GET', API_URL, requestHandler, {'content-type': 'application/json'})
}
//POST请求  
function POST(API_URL,requestHandler) {
  console.log(API_URL);
  console.log(requestHandler);
  request('POST', API_URL, requestHandler, {"content-type": "application/x-www-form-urlencoded"})
}

function request(method, API_URL, requestHandler,header) {
  //注意：可以对params加密等处理  
  var params = requestHandler.params;
  console.log(params)
  wx.request({
    url: API_URL,
    data: params,
    method: method, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT  
    // header: {}, // 设置请求的 header  
    header:header,
    success: function (res) {
      //注意：可以对参数解密等处理  
      requestHandler.success(res)
    },
    fail: function () {
      requestHandler.fail()
    },
    complete: function () {
      // complete  
    }
  })
}

module.exports = {
  GET: GET,
  POST: POST
}  